import { param2Obj } from '@/utils'

const permissionMap = {
    dba: [{
        title: 'mysql',
        name: 'mysql',
        children: [
            { title: 'SQL自助审核', name: 'sqlreview' },
            { 
                title: '创建工单', 
                name: 'workorder',
                hidden: true,
                children: [
                    { title: '创建数据库', name: 'createdb',hidden: true },
                    { title: '创建新表', name: 'createtable',hidden: true },
                    { title: '更改表结构', name: 'modifytable',hidden: true },
                    { title: '数据更改', name: 'updatedata',hidden: true},
                    { title: '导数据', name: 'exportdata',hidden: true}
                ]
            },
            {
                title: '工单列表', 
                name: 'workorderlist',
                children: [
                    { title: '待处理工单', name: 'processing' },
                    { title: '已处理工单', name: 'processed' },
                    { title: '已打回工单', name: 'refuse'},
                    { title: '所有工单', name: 'all' }
                ]
            }
        ]
    }],
    owner: [{
        title: 'mysql',
        name: 'mysql',
        children: [
            { title: 'SQL自助审核', name: 'sqlreview' },
            { 
                title: '创建工单', 
                name: 'workorder',
                children: [
                    { title: '创建数据库', name: 'createdb' },
                    { title: '创建新表', name: 'createtable' },
                    { title: '更改表结构', name: 'modifytable' },
                    { title: '数据更改', name: 'updatedata'},
                    { title: '导数据', name: 'exportdata'}
                ]
            },
            {
                title: '工单列表', 
                name: 'workorderlist',
                children: [
                    { title: '待审核工单', name: 'checking' },
                    { title: '待处理工单', name: 'processing' },
                    { title: '已处理工单', name: 'processed' },
                    { title: '已打回工单', name: 'refuse'},
                    { title: '所有工单', name: 'all' }
                ]
            }
        ]
    }],
    member: [{
        title: 'mysql',
        name: 'mysql',
        children: [
            { title: 'SQL自助审核', name: 'sqlreview' },
            { 
                title: '创建工单', 
                name: 'workorder',
                children: [
                    { title: '创建数据库', name: 'createdb' },
                    { title: '创建新表', name: 'createtable' },
                    { title: '更改表结构', name: 'modifytable' },
                    { title: '数据更改', name: 'updatedata'},
                    { title: '导数据', name: 'exportdata'}
                ]
            },
            {
                title: '工单列表', 
                name: 'workorderlist',
                children: [
                    { title: '待审核工单', name: 'checking' },
                    { title: '待处理工单', name: 'processing' },
                    { title: '已处理工单', name: 'processed' },
                    { title: '已打回工单', name: 'refuse'},
                    { title: '已废弃工单', name: 'abandon'},
                    { title: '所有工单', name: 'all' }
                ]
            }
        ]
    }]
};

export default {
    getPermissions : config => {
        const { token } = param2Obj(config.url)
        let tokenObj = JSON.parse(token)
        let { roles } = tokenObj
        
        if(permissionMap[roles[0]]){
            return permissionMap[roles[0]]
        }
        else{
            return false
        }
    }
}